<template>
  <div class="goods-item" @click="toGoodsPage(goods.id)">
    <img :src="goods.banner[0] ? goods.banner[0].url : ''" alt="" />
    <div class="title">
      {{ goods.name }}
    </div>
    <div class="tags">
      <div class="item" v-for="(item, index) in goods.promotion" :key="index">
        {{ item }}
      </div>
    </div>
    <div class="info">
      <div class="sales">
        销量 <span>{{ goods.shop_name }}</span>
      </div>
      <div class="spec">规格<span>>3种</span></div>
    </div>
    <div class="shop" @click.stop="toShopPage(goods.shop_id)">
      <span>{{ goods.shop_name }}</span
      ><icon name="iconxiangyoubeifen16" size="14" />
    </div>
    <div class="price">
      <b>¥ {{ userinfo ? goods.starting_price : "登录可见" }}</b
      ><s v-if="goods.price">¥ {{ goods.price }}</s>
    </div>
    <div class="progress">
      <div class="tit">抢购中</div>
      <div class="bar">
        <span>剩</span>
        <div class="bar-box">
          <div
            class="val"
            :style="{ width: (goods.surplus / goods.number) * 100 + '%' }"
          ></div>
        </div>
        <span>{{ (goods.surplus / goods.number) * 100 + "%" }}</span>
      </div>
    </div>
    <!-- <div class="button">即将开始</div> -->
  </div>
</template>

<script>
// 秒杀页面商品
import { mapState } from "vuex";
export default {
  name: "GoodsItem4",
  computed: {
    ...mapState("user", ["userinfo"]),
  },
  props: {
    goods: Object,
  },
};
</script>

<style lang="scss" scoped>
.goods-item {
  width: 224px;
  box-sizing: border-box;
  background: #ffffff;
  border: 1px solid #ffffff;
  border-radius: 5px;
  margin-left: 20px;
  margin-bottom: 20px;
  display: inline-block;
  position: relative;
  &:hover {
    border: 1px solid #d52c1a;
    .add-car {
      display: flex;
    }
  }
  img {
    width: 200px;
    height: 200px;
    border-radius: 5px;
    padding: 10px 12px;
  }
  .title {
    height: 44px;
    padding: 0 12px;
    font-size: 16px;
    font-weight: 400;
    color: #333333;
    line-height: 22px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .tags {
    padding: 9px 16px 7px;
    .item {
      display: inline-block;
      background: #dc2c1a;
      border-radius: 5px;
      padding: 3px 10px;
      line-height: 14px;
      font-size: 10px;
      font-weight: 400;
      color: #ffffff;
      margin-left: 12px;
      cursor: pointer;
      &:first-child {
        margin-left: 0;
      }
    }
  }
  .info {
    padding: 0 12px;
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    font-weight: 400;
    color: #999999;
    line-height: 20px;
  }
  .price {
    padding: 6px 16px 6px;
    b {
      font-size: 18px;
      font-weight: 500;
      color: #d52c1a;
      line-height: 25px;
    }
    s {
      font-size: 14px;
      font-weight: 400;
      color: #999999;
      line-height: 20px;
      padding-left: 8px;
    }
  }
  .shop {
    height: 30px;
    padding: 0 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 400;
    color: #999999;
    line-height: 20px;
    cursor: pointer;
  }
  .button {
    height: 44px;
    background: #d48d09;
    border-radius: 5px;
    padding: 0 12px;
    margin: 0 12px 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    font-weight: 400;
    color: #ffffff;
    line-height: 20px;
  }
  .progress {
    height: 44px;
    background: #d52c1a;
    border-radius: 5px;
    padding: 0 12px;
    margin: 0 12px 6px;
    display: flex;
    justify-content: center;
    flex-direction: column;
    .tit {
      font-size: 14px;
      font-weight: 400;
      color: #ffffff;
      line-height: 20px;
    }
    .bar {
      align-items: center;
      display: flex;
      justify-content: space-between;
      span {
        font-size: 12px;
        font-weight: 400;
        color: #ffffff;
        line-height: 17px;
      }
      .bar-box {
        width: 120px;
        height: 8px;
        background: rgba(255, 255, 255, 0.5);
        border-radius: 5px;
        overflow: hidden;
        .val {
          height: 100%;
          background: #fff;
          border-radius: 5px;
        }
      }
    }
  }
}
</style>
